package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class FIND extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    int i = 0;
    if (paramArrayOfObject.length > 2)
    {
      Object localObject3 = paramArrayOfObject[2];
      if (localObject3 instanceof Number)
        i = ((Number)localObject3).intValue();
    }
    int j = "" + localObject2.indexOf("" + localObject1, i);
    ++j;
    return new Integer(j);
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "FIND(find_text,within_text,start_num): 在文本串中查找另一文本串，并且从within_text中的第一个字符开始返回到find_text的起始位置编号。也可以使用SEAERCH函数在文本串中查找另一文本串，所不同的是FIND函数能区分大小写，但不允许使用通配符。\nFind_text:需要查找的文本或包含文本的单元格引用。\nWithin_text:包含需要查找文本的文本或单元格引用。\nStart_num:指定进行查找字符的起始位置。在within_text中起始位置字符编号为1。如果省略start_num，则假设值为1。\n备注:\n    如果find_text不在within_text中，FIND函数返回错误信息*VALUE!。\n    如果start_num不大于0，FIND函数返回错误信息*VALUE!。\n    如果start_num大于within_text的长度，FIND函数返回错误信息*VALUE!。\n    如果find_text是空白文本，FIND函数将在搜索串中匹配第一个字符（即编号为start_num或1的字符）。\n示例:\nFIND(\"I\",\"Information\")等于1。\nFIND(\"i\",\"Information\")等于9。\nFIND(\"o\",\"Information\",2)等于4。\nFIND(\"o\",\"Information\",12)等于*VALUE!。";
  }

  public String getEN()
  {
    return "FIND(find_text,within_text,start_num): FIND finds one text string (find_text) within another text string (within_text), and returns the number of the starting position of find_text, from the first character of within_text. You can also use SEARCH to find one text string within another, but unlike SEARCH, FIND is case sensitive and doesn't allow wildcard characters.\nFind_text is the text you want to find.\nWithin_text is the text containing the text you want to find.\nStart_num specifies the character at which to start the search. The first character in within_text is character number 1. If you omit start_num, it is assumed to be 1.\n\nRemarks:\n1. If start_num is not greater than zero, FIND and FINDB return the #VALUE! error value. \n2. If start_num is not greater than zero, FIND and FINDB return the #VALUE! error value. \n3. If start_num is greater than the length of within_text, FIND and FINDB return the #VALUE! error value.\n4. If find_text is \"\" (empty text), FIND matches the first character in the search string (that is, the character numbered start_num or 1). \n\nExample:\n   FIND(\"I\",\"Information\") = 1\n   FIND(\"i\",\"Information\") = 9\n   FIND(\"o\",\"Information\",2) = 4\n   FIND(\"o\",\"Information\",12) = *VALUE!";
  }
}